﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class AdminLogin : System.Web.UI.Page
{
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    string strconn;

    protected void Page_Load(object sender, EventArgs e)
    {
        strconn = WebConfigurationManager.ConnectionStrings["photoconnection"].ToString();
        conn = new SqlConnection(strconn);
        ds = new DataSet();
        if (!IsPostBack)
            load();
    }
    public void load()
    {
        try
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            cmd = new SqlCommand("adminselect", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            conn.Close();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            cmd = new SqlCommand("adminlogin", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = txtuser.Text;
            cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = txtpass.Text;
            //lbl1.Text = "success";

            object i = cmd.ExecuteScalar();
            if (i != null)
            {
                lbl1.Text = "success"; //dUNG'
                Response.Redirect("AdminPage.aspx");
            }
            else
                lbl1.Text = "false";//SAI
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            conn.Close();
        }
    }
}